import request from '@/utils/request'

export interface FavoriteItem {
  id: number
  problem_id: number
  problem_title: string
  notes: string
  created_at: string
}

export const addFavorite = (problemId: number) => {
  return request({
    url: '/users/favorite/add_favorite/',
    method: 'post',
    data: { problem_id: problemId }
  })
}

export const removeFavorite = (problemId: number) => {
  return request({
    url: '/users/favorite/remove_favorite/',
    method: 'post',
    data: { problem_id: problemId }
  })
}

export const listFavorites = () => {
  return request<FavoriteItem[]>({
    url: '/users/favorite/list_favorites/',
    method: 'get'
  })
}

export const updateNotes = (problemId: number, notes: string) => {
  return request({
    url: '/users/favorite/update_notes/',
    method: 'post',
    data: {
      problem_id: problemId,
      notes
    }
  })
}
